﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
namespace CricketHub
{
    public class webRequesting_country
    {
        HttpWebRequest request;
        public CountryDetails1 det;
        public void webRequest()
        {
            try
            {
                var cuntyvalue = App.Current as App;
                string cvalue = cuntyvalue.countries;
                request = (HttpWebRequest)WebRequest.Create("http://www.myworkdemos.com/sports/JayaRama/getdata.php?id=" + cvalue);
                IAsyncResult result = (IAsyncResult)request.BeginGetResponse(new AsyncCallback(Resp), this);
            }
            catch (Exception)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show("Please check the network connection");
                });
            }

 
        }
        private void Resp(IAsyncResult asyn)
        {
            try
            {
                webRequesting_country webrequest = (webRequesting_country)asyn.AsyncState;
                HttpWebRequest request1 = request;
                HttpWebResponse response = (HttpWebResponse)request1.EndGetResponse(asyn);
                Stream streamdata = response.GetResponseStream();
                StreamReader reader = new StreamReader(streamdata);
                string content = reader.ReadToEnd();
                System.Diagnostics.Debug.WriteLine("the data is ......................" + content);
                det.UpdateData(content);
            }
            catch (Exception jj)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show("Please check the network connection");
                });
            }
        }

    }
}
